﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Data.SqlClient;
using ServiceDeskUNAB.Controlador;
using ServiceDeskUNAB.Modelo;

namespace ServiceDeskUNAB.Vista
{
    public partial class NuevaUrgenciaVista : UserControl
    {
        public NuevaUrgenciaVista()
        {
            InitializeComponent();
        }

        private void agregarBtn_Click(object sender, EventArgs e)
        {
            Conexion.Instance.Ingresar("SEVERIDAD", nuevaCatTxt.Text);
            using (Conexion.Instance.Con) //With this, you don't have to close the connection
            {

                SqlDataAdapter adapter = new SqlDataAdapter("select * from URGENCIA", Conexion.Instance.Con);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "URGENCIA");
                dataGridViewRoles.DataSource = ds;
                dataGridViewRoles.DataMember = "URGENCIA";
            }
        }

        private void NuevaCategoriaIncidenciasVista_Load(object sender, EventArgs e)
        {
            using (Conexion.Instance.Con) //With this, you don't have to close the connection
            {

                SqlDataAdapter adapter = new SqlDataAdapter("select * from URGENCIA", Conexion.Instance.Con);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "URGENCIA");
                dataGridViewRoles.DataSource = ds;
                dataGridViewRoles.DataMember = "URGENCIA";
            }
        }

       

        private void dataGridViewCategorias_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridViewRoles.SelectedCells.Count > 0)
            {
                int selectedrowindex = dataGridViewRoles.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridViewRoles.Rows[selectedrowindex];

                string id = Convert.ToString(selectedRow.Cells[this.dataGridViewRoles.Columns[0].Name].Value);
                string nombre = Convert.ToString(selectedRow.Cells[this.dataGridViewRoles.Columns[1].Name].Value);
                idBox.Text = id;
                nombreTxt.Text = nombre;
            }
        }

        private void buscarBtn_Click(object sender, EventArgs e)
        {
            CategoriaIncidencia ci = CategoriaIncidenciaControlador.Instance.Buscar(idBox.Text);
            if (ci == null)
                MessageBox.Show("No se encuentra Categoria");
            else
                nombreTxt.Text = ci.NombreCategoriaIncidencia;

        }

        private void eliminarBtn_Click(object sender, EventArgs e)
        {

        }
    }
}
